﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project362.Files;

namespace Project362.Collections
{
    public class Collection
    {
        private Dictionary<string, FileClass> dir;
        /// <summary>
        /// Initializes a new collection
        /// </summary>
        public Collection()
        {
            dir = new Dictionary<string, FileClass>();
        }
        /// <summary>
        /// Adds a file to this collection
        /// </summary>
        /// <param name="filename">Location of file to add</param>
        /// <returns>success or failure</returns>
        public bool addFile(string filename)
        {
            FileClass f = new FileClass(filename);
            dir.Add(filename, f);
            return true;
        }
        /// <summary>
        /// Adds a file to this collection
        /// </summary>
        /// <param name="file">FileClass object (already constructed)</param>
        /// <returns>Success or failure</returns>
        public bool addFile(FileClass file)
        {
            dir.Add(file.Filename, file);
            return true;
        }
        /// <summary>
        /// Removes a file from this collection
        /// </summary>
        /// <param name="filename">location of file to remove</param>
        /// <returns>success or failure</returns>
        public bool removeFile(string filename)
        {
            if (!dir.ContainsKey(filename)) { return false; }
            else
            {
                dir.Remove(filename);
                return true;
            }
        }
        /// <summary>
        /// Removes a file from this collection
        /// </summary>
        /// <param name="file">FileClass object to remove</param>
        /// <returns>success or failure</returns>
        public bool removeFile(FileClass file)
        {
            if (!dir.ContainsKey(file.Filename)) { return false; }
            else
            {
                dir.Remove(file.Filename);
                return true;
            }
        }
        /// <summary>
        /// get files in this collection
        /// </summary>
        /// <returns>a list of all fileclass objects this collection stores</returns>
        public List<FileClass> getFiles()
        {
            List<FileClass> l = new List<FileClass>();
            foreach (FileClass f in dir.Values)
            {
                l.Add(f);
            }
            return l;
        }
        /// <summary>
        /// Check if this collection contains a particular file
        /// </summary>
        /// <param name="filename">File to check</param>
        /// <returns>Yes or no</returns>
        public bool contains(string filename)
        {
            return dir.ContainsKey(filename);
        }
        /// <summary>
        /// Get a fileclass object from this collection
        /// </summary>
        /// <param name="filename">location of object to get</param>
        /// <returns>FileClass object or null</returns>
        public FileClass getFile(string filename)
        {
            if (!dir.ContainsKey(filename)) { return null; }
            else
            {
                return dir[filename];
            }
        }
    }
}
